package com.zc.blog.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class EmailUtil{

    private static final String EMAIL_REGEX = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";

    /**
     * 验证邮箱格式
     *
     * @param email 要验证的邮箱
     * @return 邮箱格式正确返回 true，否则返回 false
     */
    public static boolean isValidEmail(String email) {
        if (email == null || email.isEmpty()) {
            return false;
        }

        // 创建一个模式对象
        Pattern pattern = Pattern.compile(EMAIL_REGEX);
        Matcher matcher = pattern.matcher(email);

        // 检查邮箱是否匹配正则表达式
        return matcher.matches();
    }

    public static void main(String[] args) {
        String email = "zc@??.com";
        System.out.println(isValidEmail(email));
    }
}

